#!/bin/sh

# Configuration of the bridge should be done in /etc/network/interfaces.d/bridgeX
# Read more at https://wiki.debian.org/BridgeNetworkConnections

. /usr/share/common

if [ ! -x /sbin/brctl ]; then
	echo_error "No bridge ports control utility"
	exit 0
fi

if [ -z "$IF_BRIDGE_PORTS" ]; then
	echo_error "No bridge ports defined"
	exit 0
fi

case "$IF_BRIDGE_PORTS" in
	none)
		INTERFACES=""
		;;
	all)
		INTERFACES=$(grep eth /proc/net/dev | sed 's/\(\ *\)\(eth[^:]*\)\(.*\)/\2/')
		;;
	*)
		INTERFACES="$IF_BRIDGE_PORTS"
		;;
esac

brctl delbr $IFACE

for i in $INTERFACES; do
	echo_info "Bringing down $i"
	ip link set $i down
done
